<?php
namespace application\admin\panels;

use application\utilities\Utility;
class start extends panel {
	public $name = 'Welcome to Concerto';
	
	

	
	public function handleData() {
		global $concerto;

		if($_SESSION['fresh_install']) {
			$format = $_SESSION['site_format'];
			if($format) {
				require CN_APPLICATION_PATH . 'formats/'.$format.'/install.php';
				setOption('site_format', $format);
				$this->addMessage('success', ucwords($format).' format installed.');
			}
			unset($_SESSION['fresh_install']);
		}
		if($_REQUEST['clear_errors']) {
			DB()->query("DELETE FROM `cn_pageviews` WHERE `pv_type`='error'");
			$this->successes[] = 'Errors cleared successfully.';
		}
		
		elseif($_REQUEST['send_feedback']) {
			/** For now, just send us feedback via e-mail */
			$from = $concerto->User->email;
			$message = $_REQUEST['feedback'];
			mail('jason@limitdesigns.com', 'Concerto Feedback', $message, 'From: '.$from);
			$messages['success'] = "Thanks for sending us some feedback. We'll get back to you soon.";
			$this->mergeMessages($messages);
		}
		
		// Check for updates
		/**if($contents = self::checkForUpdates()) {
			$this->alerts[] = 'A new version of Concerto ('.$contents->version.') is available. Click <a href="'.CN_URL.'admin/?display=update">here</a> to install';
			$this->alerts[] = '<b>Version Notes: </b><br />'.$contents->notes;
		
		}*/
		
		$stubs = DB()->getCount("SELECT * FROM `cn_content` WHERE `content_status`='stub'");
		$stubTypes = DB()->getResults("SELECT `ct_plural`, `ct_id`, COUNT(`content_id`) AS `count` FROM `cn_content` INNER JOIN `cn_content_types` ON `content_type`=`ct_id` WHERE `content_status`='stub' GROUP BY (`content_type`)");
		if($stubs) {
			$stubTypeText = array();
			foreach($stubTypes as $stub) {
				$stubTypeText[] = '<i>'.$stub->count . ' <b><a href="?display=manage&type='.$stub->ct_id.'&status=stub">' . $stub->ct_plural.'</a></b></i>';
			}
			$stubTypeText = implode(', ', $stubTypeText);
			$this->addMessage('alert', 'You have '.$stubs.' stub(s) to fill out. <br />'.$stubTypeText);
		
		}
		
		$pendings = DB()->getCount("SELECT * FROM `cn_content` WHERE `content_status`='pending'");
		$pendingTypes = DB()->getResults("SELECT `ct_plural`, `ct_id`, COUNT(`content_id`) AS `count` FROM `cn_content` INNER JOIN `cn_content_types` ON `content_type`=`ct_id` WHERE `content_status`='pending' GROUP BY (`content_type`)");
		if($pendings) {
			$pendingTypeText = array();
			foreach($pendingTypes as $pending) {
				$pendingTypeText[] = '<i>'.$pending->count . ' <b><a href="?display=manage&type='.$pending->ct_id.'&status=stub">' . $pending->ct_plural.'</a></b></i>';
			}
			$pendingTypeText = implode(', ', $pendingTypeText);
			$this->addMessage('alert', 'You have '.$pendings.' pending content(s) to fill out. <br />'.$pendingTypeText);
		
		}
	}
	
	protected static function checkForUpdates() {
		global $concerto;
		$contents = file_get_contents('http://www.limitdesigns.com/concerto/latest_version/version.php');
		$contents = json_decode($contents);
		$version = $contents->version;
		$currentVersion = $concerto->getOption('current_version');
		if($version > $currentVersion) return $contents;
		else return FALSE;
	}
	
	public function title() {
		return 'Welcome to Concerto.';
	}
	
	
	public function sidebar() {
		return array(
			array(
				'title'=>'Welcome',
				'sectionID'=>'welcome'
			),
			array(
				'title'=>'Start Blog',
				'sectionID'=>'blog'
			),
			array(
				'title'=>'Start Gallery',
				'sectionID'=>'gallery'
			),
			array(
				'title'=>'Start Music Site',
				'sectionID'=>'music'
			),
			array(
				'title'=>'Start Directory',
				'sectionID'=>'directory'
			),
			array(
				'title'=>'Start Club/Organization',
				'sectionID'=>'organization'
			),
			array(
				'title'=>'Start E-Commerce',
				'sectionID'=>'ecommerce'
			),
			array(
				'title'=>'Start Other',
				'sectionID'=>'other'
			)
		);
	}
	
	public function display() {
		global $concerto;
		?>
		<section id="welcome">
			<div class="box">
				<h3>Start Creating.</h3>
				<div class="box-content">
					<h4>What do you want to make today?</h4>
					<h5>We're not joking when we say you can make literally any sort of website you want with Concerto. We, the developers, have used it to make sites from a simple blog to a huge web application. To the left, you will see some of the most common Concerto set-ups to get you started. Click on them to get a detailed description of the types of content and information you will be able to use.</h5>
					<h5>If the presets aren't up to the task, you can always set up a custom structure by clicking on "start other."</h5>
					
			</div>
		</section>
		<section id="blog" style="display:none;">
		
			<div class="box">
				<h3>Start Blog</h3>
				<div class="box-content">
					<div class="two-column-left">
						<h4>What's a blog?</h4>
						<p>Okay, you probably know what a blog is. But here are the specifics of the "blog" setup.</p>
						<ul class="box-list">
							<li>
								<h5>Posts & Pages</h5>
								<p>
									Concerto blogs consist of two similar content types, the "post" and the "page".
								</p>
								<p>
									The posts are your typical blog posts, organized by date, categorized with tags, and consisting of any text, pictures, and videos you want.
								</p>
								<p>
									Pages are static, like an "about me" or "contact" page. They are essentially the same as a post, but don't have tags and are organized by title instead of date.
								</p>
							</li>
							<li>
								<h5>Reader Feedback</h5>
								<p>
									You can set up how feedback works on your posts - allow readers to react to your content with comments and/or ratings.
								</p>
							</li>
							<li>
								<h5>RSS</h5>
								<p>
									RSS (Really Simple Syndication) is automatically set up, allowing your readers to access your entire site or just posts in certain categories by using their favorite RSS reader.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</section>
		<section id="gallery" style="display:none;">
		
			<div class="box">
				<h3>Start Gallery</h3>
				<div class="box-content">
					<div class="two-column-left">
						<h4>What's a gallery?</h4>
						<p>A Concerto gallery is the easiest way to display your paintings or photography on the web. Here are the specifics of the "gallery" setup.</p>
						<ul class="box-list">
							<li>
								<h5>"Folders" and "Work"</h5>
								<p>
									In addition to a having all the capabilities of the blog setup, Concerto galleries have two other content types to handle the display and viewing of your work: the "Folder" and the "Work" (you can, and should, change the names of these to your liking during setup).
								</p>
								<p>
									Folders are organization and description tools for the work that they contain. Concerto users have used folders for art shows or photography expeditions - they are basically a way to organize your work, like tags, but also allowing for universal descriptions and themes. Keeping your work in folders is optional; some of you may find that simply using tags will suffice for your organization needs.
								</p>
								<p>
									The "work" content type is where all your actual work goes. Upload your photos, name them, tag them, describe them; it's all there and easy to use.
								</p>
							</li>
							<li>
								<h5>Beautiful Gallery Display Options</h5>
								<p>
									Gallery templates are built to beautifully display your work, not hacked together in order to display photos instead of text. 
								</p>
							</li>
							<li>
								<h5>Reader Feedback</h5>
								<p>
									You can set up how feedback works on your blog posts and your work - allow readers to react to your content with comments and/or ratings.
								</p>
							</li>
							<li>
								<h5>RSS</h5>
								<p>
									RSS (Really Simple Syndication) is automatically set up, allowing your readers to access your entire site or just posts or work in certain categories by using their favorite RSS reader.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</section>
		<section id="music" style="display:none;">
		
			<div class="box">
				<h3>Start Music Site</h3>
				<div class="box-content">
					<div class="two-column-left">
						<h4>What's a music site?</h4>
						<p>A Concerto music site is everything you need for your band or solo act. Check out the features below.</p>
						<ul class="box-list">
							<li>
								<h5>Blog</h5>
								<p>
									Keep your fans updated with blog posts with attachable songs, albums, shows, and more.
								</p>
							</li>
							<li>
								<h5>Gig Calendar</h5>
								<p>
									Easily manage and display your upcoming gigs.
								</p>
							</li>
							<li>
								<h5>Song & Album Demos</h5>
								<p>
									Using Concerto's built-in Music Player data type, you can easily upload song demos or full songs for your fans, and keep them organized by album.
								</p>
							</li>
							<li>
								<h5>Sell your Merch</h5>
								<p>
									Add those records, t-shirts, and coffee mugs to your merch section and start making cash. Automatic integration with Google Checkout or Paypal makes your life easy.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</section>
		<section id="organization" style="display:none;">
		
			<div class="box">
				<h3>Start Club/Organization Site</h3>
				<div class="box-content">
					<div class="two-column-left">
						<h4>What's a club/organization site?</h4>
						<p>Get your club or organization on the web with everything you need! Check out the features below.</p>
						<ul class="box-list">
							<li>
								<h5>News</h5>
								<p>
									Keep your members and potentials up to date with videos, pictures, and text about your organization or club.
								</p>
							</li>
							<li>
								<h5>Member Database</h5>
								<p>
									Keep up-to-date information on your members with a customizable member database, including fields for address, phone number, email, and anything else you can think of.
								</p>
							</li>
							<li>
								<h5>Event Manager</h5>
								<p>
									Plan and manage events with the easy-to-use event manager. Allow members to invite a certain amount of guests per event.
								</p>
							</li>
							<li>
								<h5>PayPal & Google Checkout Integration</h5>
								<p>
									Easily accept donations and dues with PayPal or Google Checkout.
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</section>
		
		
		<?php
	}
}
?>